package com.usian.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usian.pojo.B.day12.Contest;
import com.usian.r.R;
import com.usian.service.ContestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author BYBL
 * @date 2023/8/28
 */
@RestController
@RequestMapping("contest")
public class ContestController {
    @Autowired
    ContestService contestService;

    @RequestMapping("list")
    public R list(Contest contest){
        try {
            QueryWrapper<Contest> qw = new QueryWrapper<>();
            if (contest.getName()!=null){
                qw.like("name",contest.getName());
            }
            if (contest.getProgress()!=null){
                qw.like("progress",contest.getProgress());
            }
            List<Contest> list = contestService.list(qw);
            return R.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }
    @RequestMapping("findById")
    public R findById(Integer id){
        try {
            Contest byId = contestService.getById(id);
            return R.success(byId);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }
}
